﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Bifrost;

namespace TextEditor.TextDocument.Control
{
    public class AutoShowBapfMeg : AutoMsgBase
    {
        ZYTextBapfMark bapf = null;
        public AutoShowBapfMeg(ZYTextBapfMark _bapf)
        {
            bapf = _bapf;
            this.element = _bapf;
            this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.Width = 200;
            this.Height = 50;
            this.BackColor = System.Drawing.Color.Orange;
            this.Text = "病案评分：" + "\r\n    " + _bapf.Sign;

            if (_bapf.OwnerDocument.isHavePf())
            {
                buttonForLabel deLabel = new buttonForLabel();
                deLabel.Text = "删除";
                deLabel.Click += new EventHandler(deLabel_Click);

                buttonForLabel seLabel = new buttonForLabel();
                seLabel.Text = "查看";
                seLabel.Click += new EventHandler(seLabel_Click);
                this.Controls.Add(seLabel);
                seLabel.Location = new Point(170, 0);

                this.Controls.Add(deLabel);
                deLabel.Location = new Point(140, 0);
            }
            else
            {
                if (_bapf.OwnerDocument.Us.InpatientInfo != null && _bapf.OwnerDocument.Us.Tid > 0)
                {
                    buttonForLabel updateLabel = new buttonForLabel();
                    updateLabel.Text = "确认修改";
                    updateLabel.Click += new EventHandler(updateLabel_Click);
                    this.Controls.Add(updateLabel);
                    updateLabel.Location = new Point(145, 0);
                }
            }
        }

        void updateLabel_Click(object sender, EventArgs e)
        {
            if (this.bapf != null)
            {
                if (App.Ask("是否确认修改？"))
                {
                    if (this.bapf.OwnerDocument.isHavePfDoctor())
                    {
                        this.bapf.IsUpdate = "1";
                        this.bapf.OwnerDocument.ChangedBapfDoctor(this.bapf.Value);
                    }
                    else
                    {
                        this.bapf.IsUpdate = "1";
                    }
                }
            }
        }

        void deLabel_Click(object sender, EventArgs e)
        {
            if (this.bapf != null && !string.IsNullOrEmpty(this.bapf.Value))
            {
                bapf.Parent.ChildElements.Remove(bapf);
                bapf.OwnerDocument.ContentChanged();
                this.bapf.OwnerDocument.ChangedBapf(this.bapf.Value, 1);
            }
        }

        void seLabel_Click(object sender, EventArgs e)
        {
            if (this.bapf != null && !string.IsNullOrEmpty(this.bapf.Value))
            {
                this.bapf.OwnerDocument.ChangedBapf(this.bapf.Value, 0);
            }
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (bapf != null && bapf.IsUpdate == "1")
            {
                if (this.BackColor != System.Drawing.Color.Green)
                {
                    this.BackColor = System.Drawing.Color.Green;
                }
            }
            if (bapf == null || bapf.Deleteted || bapf.Parent.IndexOf(bapf) == -1)
            {
                if (bapf.OwnerDocument.OwnerControl.Controls.Contains(this))
                    bapf.OwnerDocument.OwnerControl.Controls.Remove(this);
                //this.Dispose();
            }
            base.OnPaint(e);
        }
    }
}
